from .celery import app
#发送邮件
@app.task
def send_email(recv,code,sender="13510391274@163.com", passward='IMJBAXPFAUJSXSUZ'):
    from studentSystemt.utils import email
    email_obj = email.Send_mail(sender=sender, passward=passward, receivers=recv)
    name = 'xxx邮件'
    text = f'您的验证码是:{code}'
    head = '路飞学城验证码：若非本人操作，请忽略此消息！！'
    #'IMJBAXPFAUJSXSUZ'
    email_obj.send(Name=name, ShowText=text, Header_show=head)
    return code

from  django.core.cache import cache

'''celery导入django框架的模块，路径尽可能的短，不然会报错的。'''
from user import models
from user import serializer

#这个学校公告的消息
@app.task
def school_messege():
    messeges = cache.get('redis_messege_all')
    if not messeges:
        mes = models.SchoolMessege.objects.all()
        ser = serializer.MessegeSerializer(instance=mes,many=True)
        messeges = cache.set('redis_messege_all',ser.data)
        return '设置成功'
    return 123